package com.cn.mmd.controller;
import com.cn.mmd.mapper.CourseMapper;
import com.cn.mmd.model.*;
import com.cn.mmd.service.*;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 定时统计类
 * Created by Administrator on 2016/8/24.
 */
//
//@Controller
//
@RequestMapping(value = "/StatisticsController")
public class StatisticsController {

    @Autowired
    TeacherService teacherService;
    @Autowired
    MajorCourseNumController majorCourseNumController;
    @Autowired
    EvaluateTeacherService evaluateTeacherService;
    @Autowired
    LeadershipService leadershipService;
    @Autowired
    CourseWeeklyService courseWeeklyService;
    @Autowired
    CourseService courseService;
    @Autowired
    StuCourseLabelService stuCourseLabelService;
    @Autowired
    LabelService labelService;
    @Autowired
    StudentService studentService;
    @Autowired
    EvaluateStaService evaluateStaService;
    @Autowired
    JPushController jPushController;


    /**
     * 月统计评价总概况
     * @throws Exception
     */
    public synchronized void EvaluateMonthStatistics() throws Exception {
//        Date now = new Date();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
//        String nowTime = dateFormat.format( now );//时间
        Date date2=new Date();
        Date date1=new Date(date2.getTime()-1000*60*60*2);
        System.out.println("获取到的时间："+date1);
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(date1);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH)+1;
        int date = calendar.get(Calendar.DATE);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
//        int second = calendar.get(Calendar.SECOND);

        String nowTime=year + "-" + month + "-" + date + " " +hour + ":" +minute + ":" + 10;

        String statisticsTheMonth=month+"月";
        System.out.println("时间："+nowTime+"====月："+statisticsTheMonth);
        AvgSchool avgSchool=teacherService.selectAvgSchool();
        String schoolName="";

        if (avgSchool!=null&&avgSchool.getTwoindexscore()!=null) {

            schoolName=avgSchool.getSchoolid();//学校名
            System.out.println("进入学校："+schoolName);
//            System.out.println("二级指标："+avgSchool.getTwoindexscore());
            String [] twoIndexScores=avgSchool.getTwoindexscore().split("!!");//这是最新的二级指标得分
            System.out.println("最新的二级指标得分："+twoIndexScores);
            String statisticsResultMonth=""; //当前月份的二级指标的分统计  格式：二级指标1_总得分_总人数！！二级指标2_总得分_总人数。。
            System.out.println("查询统计");
            MonthStatistics monthStatistics1=evaluateStaService.selectMonthStatistics(schoolName);
            System.out.println("通过学校名查："+monthStatistics1);
            if (monthStatistics1!=null){
                String [] lastTwoIndexScores=monthStatistics1.getStatisticsresult().split("!!");//这是截止上个月的二级指标得分   最新的 - 截止上个月的 = 这个月的单独的

                Map<String,Object> floatMap1=new HashMap<String, Object>();
                Map<String,Object> floatMap2=new HashMap<String, Object>();
                for (int a=0;a<twoIndexScores.length;a++){//最新的二级指标得分

                    String twoIndex=twoIndexScores[a].split("_")[0];//二级指标名
                    float sumScore=Float.parseFloat(twoIndexScores[a].split("_")[1]);//总得分
                    int sumNum=Integer.parseInt(twoIndexScores[a].split("_")[2]);//总人数
//                    float score=Float.parseFloat(twoIndexScores[a].split("_")[1])/Integer.parseInt(twoIndexScores[a].split("_")[2]);

                    floatMap1.put(twoIndex,sumScore+"_"+sumNum);
                }

                for (int a=0;a<lastTwoIndexScores.length;a++){//截止上个月的二级指标得分

                    String twoIndex=lastTwoIndexScores[a].split("_")[0];//二级指标名
                    float sumScore=Float.parseFloat(lastTwoIndexScores[a].split("_")[1]);//总得分
                    int sumNum=Integer.parseInt(lastTwoIndexScores[a].split("_")[2]);//总人数

//                    float score=Float.parseFloat(lastTwoIndexScores[a].split("_")[1])/Integer.parseInt(lastTwoIndexScores[a].split("_")[2]);

                    floatMap2.put(twoIndex,sumScore+"_"+sumNum);
                }

                for (String key:floatMap1.keySet()){
                    if (floatMap2.containsKey(key)){
                        String [] values1=floatMap1.get(key).toString().split("_");
                        String [] values2=floatMap2.get(key).toString().split("_");
                        float sumScore=Float.parseFloat(values1[0])-Float.parseFloat(values2[0]);
                        int sumNum=Integer.parseInt(values1[1])-Integer.parseInt(values2[1]);
                        if (sumScore>0&&sumNum>0) {
                            if (statisticsResultMonth.equals("")) {
                                statisticsResultMonth = key + "_" + sumScore + "_" + sumNum;
                            } else {
                                statisticsResultMonth = statisticsResultMonth + "!!" + key + "_" + sumScore + "_" + sumNum;
                            }
                        }
                    }else {
                        if (statisticsResultMonth.equals("")){
                            statisticsResultMonth=key+"_"+floatMap1.get(key);
                        }else {
                            statisticsResultMonth=statisticsResultMonth+"!!"+key+"_"+floatMap1.get(key);
                        }
                    }
                }

            }else {//上个月没有
                statisticsResultMonth=avgSchool.getTwoindexscore();
            }
//            monthStatistics1.setStatisticalobject(schoolName);



//            List<LabelTwoIndex> labelTwoIndexList=new ArrayList<LabelTwoIndex>();

//            schoolAvg=majorCourseNumController.EvaluateScore(labelTwoIndexList);


            MonthStatistics monthStatistics=new MonthStatistics();
            monthStatistics.setStatisticalobject(schoolName);
            monthStatistics.setStatisticsresult(avgSchool.getTwoindexscore());
            monthStatistics.setStatisticsresultmonth(statisticsResultMonth);
            monthStatistics.setStatisticaltime(nowTime);
            monthStatistics.setStatisticsthemonth(statisticsTheMonth);

            System.out.println("添加学校");
            evaluateStaService.insertMonthStatistics(monthStatistics);
            System.out.println("添加学校成功");
        }

//        System.out.println("进入学院！！");
        List<AvgCollege> avgCollegeList=teacherService.selectAllAvgCollege();

        if (avgCollegeList.size()>0){

            MonthStatistics monthStatistics1=null;
            for (int i=0;i<avgCollegeList.size();i++){
//                System.out.println(avgCollegeList.get(i).getCollegesum()+"===="+avgCollegeList.get(i).getCollegeheadcount()+"===="+avgCollegeList.get(i).getSchoolcollegeid());

                if (avgCollegeList.get(i).getTwoindexscore()!=null) {
                    String StatisticalObject = avgCollegeList.get(i).getSchoolcollegeid();

                    String [] twoIndexScores=avgCollegeList.get(i).getTwoindexscore().split("!!");//这是最新的二级指标得分
                    String statisticsResultMonth=""; //当前月份的二级指标的分统计  格式：二级指标1_总得分_总人数！！二级指标2_总得分_总人数。。

//                    System.out.println("学院名："+StatisticalObject);
                    MonthStatistics monthStatistics2=evaluateStaService.selectMonthStatistics(StatisticalObject);
//                    System.out.println("是不是为空了！！"+monthStatistics2);
                    if (monthStatistics2!=null){
                        String [] lastTwoIndexScores=monthStatistics2.getStatisticsresult().split("!!");//这是截止上个月的二级指标得分   最新的 - 截止上个月的 = 这个月的单独的

                        Map<String,Object> floatMap1=new HashMap<String, Object>();
                        Map<String,Object> floatMap2=new HashMap<String, Object>();
                        for (int a=0;a<twoIndexScores.length;a++){ //最新的二级指标得分

                            String twoIndex=twoIndexScores[a].split("_")[0];//二级指标名
                            float sumScore=Float.parseFloat(twoIndexScores[a].split("_")[1]);//总得分
                            int sumNum=Integer.parseInt(twoIndexScores[a].split("_")[2]);//总人数

                            floatMap1.put(twoIndex,sumScore+"_"+sumNum);
                        }

                        for (int a=0;a<lastTwoIndexScores.length;a++){//截止上个月的二级指标得分

                            String twoIndex=lastTwoIndexScores[a].split("_")[0];//二级指标名
                            float sumScore=Float.parseFloat(lastTwoIndexScores[a].split("_")[1]);//总得分
                            int sumNum=Integer.parseInt(lastTwoIndexScores[a].split("_")[2]);//总人数

                            floatMap2.put(twoIndex,sumScore+"_"+sumNum);
                        }

                        for (String key:floatMap1.keySet()){
                            if (floatMap2.containsKey(key)){
                                String [] values1=floatMap1.get(key).toString().split("_");
                                String [] values2=floatMap2.get(key).toString().split("_");
                                float sumScore=Float.parseFloat(values1[0])-Float.parseFloat(values2[0]);
//                                System.out.println("values1得分："+values1[0]+"   values2得分："+values2[0]);
                                int sumNum=Integer.parseInt(values1[1])-Integer.parseInt(values2[1]);
//                                System.out.println("values1人数："+values1[1]+"   values2人数："+values2[1]);
                                if (sumScore>0&&sumNum>0) {
                                    if (statisticsResultMonth.equals("")) {
                                        statisticsResultMonth = key + "_" + sumScore + "_" + sumNum;
                                    } else {
                                        statisticsResultMonth = statisticsResultMonth + "!!" + key + "_" + sumScore + "_" + sumNum;
                                    }
                                }
                            }else {
                                if (statisticsResultMonth.equals("")){
                                    statisticsResultMonth=key+"_"+floatMap1.get(key);
                                }else {
                                    statisticsResultMonth=statisticsResultMonth+"!!"+key+"_"+floatMap1.get(key);
                                }
                            }
                        }

                    }else {//上个月没有
                        statisticsResultMonth=avgCollegeList.get(i).getTwoindexscore();
                    }

                    monthStatistics1 = new MonthStatistics();
                    monthStatistics1.setStatisticalobject(StatisticalObject);
                    monthStatistics1.setStatisticsresult(avgCollegeList.get(i).getTwoindexscore());
                    monthStatistics1.setStatisticsresultmonth(statisticsResultMonth);
                    monthStatistics1.setStatisticaltime(nowTime);
                    monthStatistics1.setStatisticsthemonth(statisticsTheMonth);

//                    System.out.println(monthStatistics1.getStatisticalobject() + "-----" + monthStatistics1.getStatisticsresult());

                    evaluateStaService.insertMonthStatistics(monthStatistics1);
                }
            }
        }
    }


    /**
     * 周统计学生评价
     * @throws Exception 这里！！！！！！一周实际评价数
     */
    @RequestMapping(value = "weekStudentEvaluate")
    public synchronized void weekStudentEvaluate() throws Exception {

        System.out.println("进入周统计");
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//可以方便地修改日期格式
        String nowTime = dateFormat.format( now );//时间

        long weekNum=0;
        int dayForWeek1 = 0;
        //这里需要计算获取  ！！！查出第几周，周几！
        TermBeginsTime termBeginsTime=evaluateTeacherService.selectTermBeginsTime();//查出开学时间

        if (termBeginsTime!=null){
            String termTime=termBeginsTime.getTermbeginstime();

            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

            Date a1 = format .parse(nowTime);
//            System.out.println("a1:"+a1);
            Date b1 = format .parse(termTime);
//            System.out.println("b1:"+b1);
            weekNum = (a1.getTime()-b1.getTime())/(7*24*60*60*1000)+1;
//            System.out.println("weekNum:"+weekNum);
//                    /(7*24*60*60*1000)+1;

            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();
            c1.setTime(format.parse(nowTime));
            c2.setTime(format.parse(termTime));

            if(c1.get(Calendar.DAY_OF_WEEK) == 1){
                dayForWeek1 = 7;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 2){
                dayForWeek1 = 1;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 3){
                dayForWeek1 = 2;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 4){
                dayForWeek1 = 3;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 5){
                dayForWeek1 = 4;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 6){
                dayForWeek1 = 5;
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 7){
                dayForWeek1 = 6;
            }
            int dayForWeek2 = 0;
            if(c2.get(Calendar.DAY_OF_WEEK) == 1){
                dayForWeek2 = 7;
            }else{
                dayForWeek2 = c2.get(Calendar.DAY_OF_WEEK) - 1;
            }

            if (dayForWeek1<dayForWeek2){
                weekNum=weekNum+1;
            }
        }
        System.out.println("当前周数："+weekNum);
//
//
        weekNum=2;
//        System.out.println("设置的周："+weekNum);
        List<StudentEvaluate> studentEvaluateList=leadershipService.selectStudentEvaluateByTime((int)weekNum);//得到所有当前周评价了的专业
        System.out.println("学生评价的条数：" + studentEvaluateList.size());

        if (studentEvaluateList.size()>0){

            for(int a=0;a<studentEvaluateList.size();a++){

                int MaxEvaluateNum=majorCourseNumController.MaxEvaluateNum(studentEvaluateList.get(a).getStudentmajor(),(int)weekNum);//查出该周应评价数
                System.out.println("该周应评价数：" + MaxEvaluateNum);

                StudentEvaluate studentEvaluate=new StudentEvaluate();
                studentEvaluate.setWeeknum((int)weekNum);
                studentEvaluate.setStudentmajor(studentEvaluateList.get(a).getStudentmajor());
                int RealEvaluateNum=evaluateTeacherService.countStudentEvaluateByMajor(studentEvaluate);//一周实际评价数

                float percentageComplete=(float)RealEvaluateNum/MaxEvaluateNum;//(Math.round((RealEvaluateNum/MaxEvaluateNum)*1000))/1000;
//                System.out.println("完成率：" + percentageComplete);

                StudentEvaluateStatistics studentEvaluateStatistics=new StudentEvaluateStatistics();
                studentEvaluateStatistics.setStudentmajor(studentEvaluateList.get(a).getStudentmajor());
                studentEvaluateStatistics.setColleaguename(studentEvaluateList.get(a).getColleaguename());
                studentEvaluateStatistics.setStatisticstime(nowTime);
                studentEvaluateStatistics.setMaxevaluatenum(MaxEvaluateNum);
                studentEvaluateStatistics.setRealevaluatenum(RealEvaluateNum);
                studentEvaluateStatistics.setPercentagecomplete(percentageComplete);
                studentEvaluateStatistics.setWeeknum((int)weekNum);

                int b=leadershipService.insertStudentEvaluateStatistics(studentEvaluateStatistics);
//                if (b>0){
//                    System.out.println("评价成功！！！");
//                }
            }
        }

    }


    /**
     * 给学生推送评价的标签
     */
    @RequestMapping(value = "selectPushLabel")
    public synchronized
    @ResponseBody
    Map selectPushLabel() throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//可以方便地修改日期格式
        String nowTime = dateFormat.format( now );//时间

        long weekNum=0;
        String weekDay="";
        int dayForWeek1 = 0;

        //这里需要计算获取  ！！！查出第几周，周几！
        TermBeginsTime termBeginsTime=evaluateTeacherService.selectTermBeginsTime();//查出开学时间

        if (termBeginsTime!=null){
            String termTime=termBeginsTime.getTermbeginstime();

            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

            Date a1 = format .parse(nowTime);
//            System.out.println("a1:"+a1);
            Date b1 = format .parse(termTime);
//            System.out.println("b1:"+b1);
//获取相减后周数
            weekNum = (a1.getTime()-b1.getTime())/(7*24*60*60*1000)+1;
//            System.out.println("weekNum:"+weekNum);
//                    /(7*24*60*60*1000)+1;

            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();
            c1.setTime(format.parse(nowTime));
            c2.setTime(format.parse(termTime));

            if(c1.get(Calendar.DAY_OF_WEEK) == 1){
                dayForWeek1 = 7;
                weekDay="周日";
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 2){
                dayForWeek1 = 1;
                weekDay="周一";
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 3){
                dayForWeek1 = 2;
                weekDay="周二";
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 4){
                dayForWeek1 = 3;
                weekDay="周三";
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 5){
                dayForWeek1 = 4;
                weekDay="周四";
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 6){
                dayForWeek1 = 5;
                weekDay="周五";
            }else if (c1.get(Calendar.DAY_OF_WEEK) == 7){
                dayForWeek1 = 6;
                weekDay="周六";
            }

            int dayForWeek2 = 0;
            if(c2.get(Calendar.DAY_OF_WEEK) == 1){
                dayForWeek2 = 7;
            }else{
                dayForWeek2 = c2.get(Calendar.DAY_OF_WEEK) - 1;
            }

            if (dayForWeek1<dayForWeek2){
                weekNum=weekNum+1;
            }

        }

        //当前为第几周howManyWeeks，周几weekDay

//        int howManyWeeks=7;
//        weekDay="周日";
//        weekNum=16;
        System.out.println("获取到现在是第" + weekNum + "周  " + weekDay);



        String h=weekNum +"";
        int weekBegNum=(int)Math.ceil((float)weekNum / 4)*4;//截止周Math.ceil(c)
        int howManyWeeks=(int) weekNum;

        CourseWeekly courseWeekly=new CourseWeekly();

        courseWeekly.setCourseweeklyday(weekDay);
        courseWeekly.setCourseweeklyweek(h);

        List<CourseWeekly> courseWeeklyList=courseWeeklyService.selectByCondition(courseWeekly);//获取所有今天要上的课程

        map.put("courseWeeklyList",courseWeeklyList);
        map.put("howManyWeeks",howManyWeeks);
        map.put("weekBegNum",weekBegNum);
        map.put("dayForWeek1",dayForWeek1);
        map.put("h",h);
        map.put("nowTime",nowTime);

        return map;
    }

    /**
     * 把要给学生推送评价的标签存入数据库
     */
    @RequestMapping(value = "insertEvaluateLabel")
    public synchronized
    @ResponseBody
    void insertEvaluateLabel() throws Exception{
//        Map<String, Object> map = new HashMap<String, Object>();

//        System.out.println("调用方法！！");
        StuCourseLabel stuCourseLabel2=null;
//        List<String> lists=new ArrayList<String>();
//        Map<String,Object> stringMap=new HashMap<String, Object>();
//        Map<String, Object> map2=null;
//        List<Map> mapList=null;
//        List<Map> mapList1=null;
        List<CourseWeekly> courseWeeklyList = (List)selectPushLabel().get("courseWeeklyList");
        int howManyWeeks=(Integer)selectPushLabel().get("howManyWeeks");
        int weekBegNum=(Integer)selectPushLabel().get("weekBegNum");
        int dayForWeek1=(Integer)selectPushLabel().get("dayForWeek1");
        String h=(String)selectPushLabel().get("h");
        String nowTime=(String)selectPushLabel().get("nowTime");

        CourseWeekly courseWeekly1=null;
        if (courseWeeklyList.size()>0){

            String newTwoIndexName="";
            LabelTwoIndex labelTwoIndex=new LabelTwoIndex();
            List<LabelTwoIndex> labelTwoIndexList=labelService.selectBylabelName(labelTwoIndex);
            List<String> stringList=new ArrayList<String>();
            List<String> stringList1=new ArrayList<String>();
            for (int x=0;x<labelTwoIndexList.size();x++){
                if (labelTwoIndexList.get(x).getShouldpushtime().equals("afterClass")){//每次课后推
                    stringList.add(labelTwoIndexList.get(x).getTwoindexname());
                }else if (labelTwoIndexList.get(x).getShouldpushtime().equals("afterFourWeeks")){//每4周推
                    stringList1.add(labelTwoIndexList.get(x).getTwoindexname());
                }
            }

            for (int a=0;a<courseWeeklyList.size();a++){

//                System.out.println("课程id："+courseWeeklyList.get(a).getCourseid());
                Course course=courseService.selectByKey(courseWeeklyList.get(a).getCourseid());
                String teacherIds=course.getCourseteacherid();//教师id  有的是 A/B 这个格式  需分割
                String courseName=course.getCoursename();//课程名
                String classGroup=course.getCourseclasss();//班级组
                String [] classes=classGroup.split(",");

//                System.out.println("找到的课程："+course+"----教师："+teacherIds+"----班级组："+classGroup);
                //判断当前课程是不是当前周最后一节
                int everyFourWeeks=0;//判断是否该推送4周一次的二级指标，0为不是，1为是
                int y=0;//从这里！！！！！！！！！！！11
//                System.out.println("开始第几周判断000"+howManyWeeks+"   "+weekBegNum);
                for (int d=howManyWeeks+1;d<=weekBegNum;d++){
//                    System.out.println("进入第几周判断111");
                    String d1=d+"";
//                    System.out.println("进入第几周判断222");
                    courseWeekly1=new CourseWeekly();
                    courseWeekly1.setCourseid(courseWeeklyList.get(a).getCourseid());
                    courseWeekly1.setCourseweeklyweek(d1);
//                    System.out.println("进入第几周判断333");
                    List<CourseWeekly> courseWeeklyList1=courseWeeklyService.selectByCondition(courseWeekly1);
//                    System.out.println("进入第几周判断444");
                    if (courseWeeklyList1.size()>0){
                        y=y+1;
                    }
//                    System.out.println("进入第几周判断"+d1+"  ："+y);
                }
                if (y==0){

                    if (dayForWeek1<7) {

                        for (int f = dayForWeek1 + 1; f < 8; f++) {
                            String weekday = "";
                            if (f == 1) {
                                weekday = "周一";
                            } else if (f == 2) {
                                weekday = "周二";
                            } else if (f == 3) {
                                weekday = "周三";
                            } else if (f == 4) {
                                weekday = "周四";
                            } else if (f == 5) {
                                weekday = "周五";
                            } else if (f == 6) {
                                weekday = "周六";
                            } else if (f == 7) {
                                weekday = "周日";
                            }
                            courseWeekly1 = new CourseWeekly();
                            courseWeekly1.setCourseid(courseWeeklyList.get(a).getCourseid());
                            courseWeekly1.setCourseweeklyweek(h);
                            courseWeekly1.setCourseweeklyday(weekday);

                            List<CourseWeekly> courseWeeklyList2 = courseWeeklyService.selectByCondition(courseWeekly1);

                            if (courseWeeklyList2.size() > 0) {
                                //后面没课了，今天就该推送每4周一次的指标
                                everyFourWeeks=1;
                            }
//                            System.out.println("进入周几判断"+weekday+"  ："+everyFourWeeks);
                        }
                    }else {
                        //今天就该推送每4周一次的指标
                        everyFourWeeks=1;
                    }
                }

//                System.out.println("今天是不是该推4周一次的指标？"+everyFourWeeks+"     课程：" + courseWeeklyList.get(a).getCourseid());
                for (int b=0;b<classes.length;b++) {
//                    lists.add(classes[b]);
//                    stringMap.put(classes[b],1);
                    if (everyFourWeeks==1){
                        //这里！~！ 推送4周一次的指标
//                        StuCourseLabel stuCourseLabel1 = new StuCourseLabel();
//                        stuCourseLabel1.setCourseid(courseWeeklyList.get(a).getCourseid());
//                        stuCourseLabel1.setStudentclass(classes[b]);
//                        stuCourseLabel1.setShouldpushtime("afterFourWeeks");
//
//                        List<StuCourseLabel> stuCourseLabel = stuCourseLabelService.selectLastByClass(stuCourseLabel1);

//                        if (stuCourseLabel .size()>0) {
//                            System.out.println("以前推过！！");

//                            List<String> list=new ArrayList<String>();
//                            for (StuCourseLabel stuCourseLabel3:stuCourseLabel){
//
//                                String twoIndexName=stuCourseLabel3.getTwoindexname();//到这里！！！！！！！！！！！！！！！！！
////                                list.add(twoIndexName);
//                                int x=stringList1.indexOf(twoIndexName);
//                                if (x==stringList1.size()-1){
//                                    x=0;
//                                }else {
//                                    x=x+1;
//                                }
                        for (int x=0;x<stringList1.size();x++){
//                                list.add(stringList1.get(x));
                                if (teacherIds != null) {

                                    String[] teachers = teacherIds.split("/");
                                    for (String teacherId : teachers) {
                                        stuCourseLabel2 = new StuCourseLabel();

                                        TeacherData teacherData = teacherService.selectByTeacherId(teacherId);
                                        if (teacherData != null) {
                                            String headPortrait = teacherData.getTeacherheadportrait();//头像
                                            String teacherName = teacherData.getTeachername();//姓名

                                            stuCourseLabel2.setStudentclass(classes[b]);//班级
                                            stuCourseLabel2.setCourseid(courseWeeklyList.get(a).getCourseid());//课程id
                                            stuCourseLabel2.setCoursename(courseName);//课程名
                                            stuCourseLabel2.setTeacherid(teacherId);//教师id
                                            stuCourseLabel2.setTeachername(teacherName);//教师名
                                            stuCourseLabel2.setTeacherheadportrait(headPortrait);//教师头像
                                            stuCourseLabel2.setTwoindexname(stringList1.get(x));//推送的二级指标名
                                            stuCourseLabel2.setPushtime(nowTime);//推送时间
                                            stuCourseLabel2.setShouldpushtime("afterFourWeeks");

                                            stuCourseLabelService.insertStuCourseLabel(stuCourseLabel2);
                                        }
                                    }
                                }
                            }
//                        }
//                        else {
////                            System.out.println("以前没推过！！");
//
//                            for (int g=0;g<2;g++){
//
//                                if (teacherIds != null) {
//
//                                    String[] teachers = teacherIds.split("/");
//                                    for (String teacherId : teachers) {
//                                        stuCourseLabel2 = new StuCourseLabel();
//
//                                        TeacherData teacherData = teacherService.selectByTeacherId(teacherId);
//                                        if (teacherData != null) {
//                                            String headPortrait = teacherData.getTeacherheadportrait();//头像
//                                            String teacherName = teacherData.getTeachername();//姓名
//
//                                            stuCourseLabel2.setStudentclass(classes[b]);//班级
//                                            stuCourseLabel2.setCourseid(courseWeeklyList.get(a).getCourseid());//课程id
//                                            stuCourseLabel2.setCoursename(courseName);//课程名
//                                            stuCourseLabel2.setTeacherid(teacherId);//教师id
//                                            stuCourseLabel2.setTeachername(teacherName);//教师名
//                                            stuCourseLabel2.setTeacherheadportrait(headPortrait);//教师头像
//                                            stuCourseLabel2.setTwoindexname(stringList1.get(g));//推送的二级指标名
//                                            stuCourseLabel2.setPushtime(nowTime);//推送时间
//                                            stuCourseLabel2.setShouldpushtime("afterFourWeeks");
//
//                                            stuCourseLabelService.insertStuCourseLabel(stuCourseLabel2);
//                                        }
//                                    }
//                                }
//                            }
//                        }
                    }
                    StuCourseLabel stuCourseLabel1 = new StuCourseLabel();
                    stuCourseLabel1.setCourseid(courseWeeklyList.get(a).getCourseid());
                    stuCourseLabel1.setStudentclass(classes[b]);
                    stuCourseLabel1.setShouldpushtime("afterClass");
                    //查到班级！

                    List<StuCourseLabel> stuCourseLabel = stuCourseLabelService.selectLastByClass(stuCourseLabel1);
//                    System.out.println("查出来的长度："+stuCourseLabel.size());

                    if (stuCourseLabel.size()>0) {
//                        System.out.println("以前推过！！");
                        String twoIndexName = stuCourseLabel.get(0).getTwoindexname();//查到这个班级这门课程上次推的是哪一个二级指标

                        int x = stringList.indexOf(twoIndexName);
                        if (x < stringList.size() - 1 && x >= 0) {
                            newTwoIndexName = stringList.get(x+1);
                        } else if (x == stringList.size() - 1) {
                            newTwoIndexName = stringList.get(0);
                        } else if (x == -1) {
                            newTwoIndexName = stringList.get(0);//这次该推的二级指标
                        }

                        if (teacherIds != null) {

                            String[] teachers = teacherIds.split("/");
                            for (String teacherId : teachers) {
                                stuCourseLabel2 = new StuCourseLabel();

                                TeacherData teacherData = teacherService.selectByTeacherId(teacherId);
                                if (teacherData != null) {
                                    String headPortrait = teacherData.getTeacherheadportrait();//头像
                                    String teacherName = teacherData.getTeachername();//姓名

                                    stuCourseLabel2.setStudentclass(classes[b]);//班级
                                    stuCourseLabel2.setCourseid(courseWeeklyList.get(a).getCourseid());//课程id
                                    stuCourseLabel2.setCoursename(courseName);//课程名
                                    stuCourseLabel2.setTeacherid(teacherId);//教师id
                                    stuCourseLabel2.setTeachername(teacherName);//教师名
                                    stuCourseLabel2.setTeacherheadportrait(headPortrait);//教师头像
                                    stuCourseLabel2.setTwoindexname(newTwoIndexName);//推送的二级指标名
                                    stuCourseLabel2.setPushtime(nowTime);//推送时间
                                    stuCourseLabel2.setShouldpushtime("afterClass");

                                    stuCourseLabelService.insertStuCourseLabel(stuCourseLabel2);

                                }
                            }
                        }

                    } else {
                        //以前没有推过
//                        System.out.println("以前没有推过" + classes[b]);
                        newTwoIndexName = stringList.get(0);

//                        System.out.println("教师id未分割："+teacherIds);
                        if (teacherIds != null) {

                            String[] teachers = teacherIds.split("/");
                            for (String teacherId : teachers) {

                                stuCourseLabel2 = new StuCourseLabel();
//                                System.out.println("教师id:"+teacherId);
                                TeacherData teacherData = teacherService.selectByTeacherId(teacherId);
                                if (teacherData != null) {
//                                    System.out.println("查到教师");
                                    String headPortrait = teacherData.getTeacherheadportrait();//头像
                                    String teacherName = teacherData.getTeachername();//姓名

                                    stuCourseLabel2.setStudentclass(classes[b]);//班级
                                    stuCourseLabel2.setCourseid(courseWeeklyList.get(a).getCourseid());//课程id
                                    stuCourseLabel2.setCoursename(courseName);//课程名
                                    stuCourseLabel2.setTeacherid(teacherId);//教师id
                                    stuCourseLabel2.setTeachername(teacherName);//教师名
                                    stuCourseLabel2.setTeacherheadportrait(headPortrait);//教师头像
                                    stuCourseLabel2.setTwoindexname(newTwoIndexName);//推送的二级指标名
                                    stuCourseLabel2.setPushtime(nowTime);//推送时间
                                    stuCourseLabel2.setShouldpushtime("afterClass");

//                                    System.out.println("添加操作");
                                    stuCourseLabelService.insertStuCourseLabel(stuCourseLabel2);
//                                    System.out.println("添加操作完成");
                                }
                            }
                        }
                    }
                }
            }
        }
        //极光推送
//        for (String key:stringMap.keySet()){
//            System.out.println("班级："+key);
//            jPushController.testSendPush1("今天别忘了吱一下哦", key);
//        }
    }

    /**
     * 推送学生评价标签  极光推送
     * @throws Exception
     */
    @RequestMapping(value = "pushEvaluateLabel")
    public synchronized
    @ResponseBody
    void pushEvaluateLabel() throws Exception{
//        Date date=new Date();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//可以方便地修改日期格式
//        String nowTime = dateFormat.format(date);//时间
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1); //得到前搜索一天
        Date date = calendar.getTime();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String data1=df.format(date);

        List<StuCourseLabel> stuCourseLabelList=stuCourseLabelService.selectClassShouldPush(data1);

        if (stuCourseLabelList.size()>0){
            for (StuCourseLabel stuCourseLabel:stuCourseLabelList){
//                System.out.println("班级："+stuCourseLabel.getStudentclass());
                jPushController.testSendPush1("今天别忘了吱一下哦", stuCourseLabel.getStudentclass());
            }
        }
    }

}
